﻿using System;
using System.Linq;

namespace IInject.Registration.Scanning
{
	/// <summary>
	/// Registers all the types that inherit the type provided.
	/// </summary>
	public class BaseTypeScanningRule : PublicClassScanningRule
	{
		public BaseTypeScanningRule(Type baseType)
		{
			BaseType = baseType;
		}

		public override ScanningRuleType Type
		{
			get
			{
				return ScanningRuleType.Inherits;
			}
		}

		public Type BaseType { get; private set; }

		public override MatchingResult IsMatch(Type type)
		{
			return new MatchingResult
			{
				From = type,
				IsMatch = IsPublicClass(type) && BaseType.IsAssignableFrom(type),
			};
		}
	}
}
